package demo.practice.leetcode_eveyday;

public class P1143 {


    public static void main(String[] args) {
        P1143 p1143= new P1143();
        p1143.longestCommonSubsequence("mhunuzqrkzsnidwbun","szulspmhwpazoxijwbq");  //zsiwb  zz
        /*
        * "mhunuzqrkzsnidwbun"
"szulspmhwpazoxijwbq"
        * */
    }
    //

    public int longestCommonSubsequence(String text1, String text2) {

        int max = 0;

        for (int i = 0; i < text1.length(); i++) {
            int py = 0;
            int j = i;
            //char c = text1.charAt(j);
            StringBuffer sb = new StringBuffer();//mhzq  hzq uzq zsiwb siwb iwb wb b u

            while (py < text2.length() && j < text1.length()) {
                char c = text1.charAt(j);
                if (text2.substring(py).indexOf(c) != -1) {
                    py = py+text2.substring(py).indexOf(c)+1;
                    sb.append(c);
                    j++;
                } else {
                    if (sb.length() == 0) {
                        break;
                    } else {
                        j++;

                    }
                }
            }
            max= Math.max(max,sb.length());
        }

        return max;
    }
}
